package com.kirayous.gulimall.authserver.config;


import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.fastjson.JSON;
import com.kirayous.common.exception.BizCodeEnume;
import com.kirayous.common.utils.R;
import org.springframework.context.annotation.Configuration;


@Configuration
public class AuthSentinelConfig {

    public AuthSentinelConfig(){
        WebCallbackManager.setUrlBlockHandler((request, response, ex) -> {
            R error = R.error(BizCodeEnume.TOO_MANY_REQUEST.getCode(), BizCodeEnume.TOO_MANY_REQUEST.getMsg());
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json");
            response.getWriter().write(JSON.toJSONString(error));
        });
    }
}
